package net.heartbeat.source.senders;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import net.heartbeat.source.HeartbeatSender;

/**
 * 测试类：把心跳信号打印到控制台<br>
 * 支持中文
 * 
 * @author Bai Yu
 *
 */
public class ConsoleSender implements HeartbeatSender {
	@Override
	public ConsoleOutputStream getOutputStream() {
		return new ConsoleOutputStream();
	}

	private static class ConsoleOutputStream extends OutputStream {
		public ConsoleOutputStream() {
			content = new ByteArrayOutputStream();
		}

		@Override
		public void write(int b) throws IOException {
			content.write(b);
		}

		@Override
		public void close() {
			System.out.println("[心跳]内容：" + new String(content.toByteArray()));
		}

		private ByteArrayOutputStream content;
	}

}
